<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "zt_photo".
 *
 * @property integer $photo_id
 * @property string $photo_name
 * @property string $photo_src
 * @property string $photo_description
 * @property string $photo_upload_time
 */
class ZtPhoto extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'zt_photo';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['photo_upload_time'], 'safe'],
            [['photo_name', 'photo_src', 'photo_description'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'photo_id' => 'Photo ID',
            'photo_name' => 'Photo Name',
            'photo_src' => 'Photo Src',
            'photo_description' => 'Photo Description',
            'photo_upload_time' => 'Photo Upload Time',
        ];
    }
    /*
     * 插入图片
     *
     * */
    public function insertPictureMessage($params){
        $models = new ZtPhoto();
        $models->photo_name = $params['pictureName'];
        $models->photo_src = $params['photo_src'];
        $models->photo_description = $params['pictureDescription'];
        $models->photo_upload_time =$params['upload_time'];
      return $models->save();

    }
    public function findPhotos(){
        $models = new ZtPhoto();
        $result = $models::find()
            ->select(['photo_name','photo_src','photo_upload_time'])
            ->orderBy('photo_id DESC')
            ->asArray()
            ->all();
      return $result;
    }
    public function getNewPhoto(){
        $models = new ZtPhoto();
        $result = $models::find()
            ->select(['photo_name','photo_src','photo_upload_time'])
            ->orderBy('photo_id DESC')
            ->limit(6)
            ->asArray()
            ->all();
        return $result;

    }
}
